package com.qys.livesMall.kafka.service;

import com.qys.livesMall.kafka.dao.shop.ShopGoodsInterestInfoDao;
import com.qys.livesMall.kafka.dao.shop.ShopInterestInfoDao;
import com.qys.livesMall.kafka.entity.shop.ShopGoodsInterestInfo;
import com.qys.livesMall.kafka.entity.shop.ShopInterestInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @menu InterestHandleServer
 * @date 2023/06/03 9:36
 */
@Service
public class InterestHandleServer {


    @Autowired
    public ShopInterestInfoDao shopInterestInfoDao;

    @Autowired
    public ShopGoodsInterestInfoDao shopGoodsInterestInfoDao;

    public int interest(ShopInterestInfo info){
        //查询是否已存在
        ShopInterestInfo interestInfo=shopInterestInfoDao.getAllByShopIdAndUserId(info.getShopId(), info.getUserId());
        if (interestInfo!=null){
            return 0;
        }
        shopInterestInfoDao.save(info);
        return 1;
    }

    public int interestCancel(Long shopId,Long userId){
        //查询是否已存在
        ShopInterestInfo interestInfo=shopInterestInfoDao.getAllByShopIdAndUserId(shopId, userId);
        if (interestInfo==null){
            return 0;
        }
        shopInterestInfoDao.deleteById(interestInfo.getId());
        return 1;
    }

    public int isInterestShop(Long shopId,Long userId){
        //查询是否已存在
        ShopInterestInfo interestInfo=shopInterestInfoDao.getAllByShopIdAndUserId(shopId, userId);
        if (interestInfo!=null){
            return 1;
        }
        return 0;
    }

    public int isInterestShopGoods(Long shopGoodsId,Long userId) {
        //查询是否已存在
        ShopGoodsInterestInfo interestInfo = shopGoodsInterestInfoDao.getAllByShopGoodsIdAndUserId(shopGoodsId, userId);
        if (interestInfo != null) {
            return 1;
        }
        return 0;
    }

    public int interestShopGoods(ShopGoodsInterestInfo info){
        //查询是否已存在
        ShopGoodsInterestInfo interestInfo=shopGoodsInterestInfoDao.getAllByShopGoodsIdAndUserId(info.getShopGoodsId(), info.getUserId());
        if (interestInfo!=null){
            return 0;
        }
        shopGoodsInterestInfoDao.save(info);
        return 1;
    }

    public int shopGoodsInterestCancel(Long shopGoodsId,Long userId){
        //查询是否已存在
        ShopGoodsInterestInfo interestInfo=shopGoodsInterestInfoDao.getAllByShopGoodsIdAndUserId(shopGoodsId, userId);
        if (interestInfo==null){
            return 0;
        }
        shopGoodsInterestInfoDao.deleteById(interestInfo.getId());
        return 1;
    }
}

